package com.zany.children.service;

import com.zany.children.dao.ClassDao;
import com.zany.children.dao.TeacherDao;
import com.zany.children.vo.Class;
import com.zany.children.vo.Teacher;

import java.util.List;
import java.util.Map;

public class TeacherServiceImpl implements TeacherService {

    private TeacherDao teacherDao;


    public TeacherDao getTeacherDao() {
        return teacherDao;
    }

    public void setTeacherDao(TeacherDao teacherDao) {
        this.teacherDao = teacherDao;
    }


    @Override
    public List<Teacher> getTeacherListPage(Map<String,Object> teacher) {
        return teacherDao.getTeacherListPage(teacher);
    }

    @Override
    public Integer getTeacherListPageCount(Map<String,Object> teacher) {
        return teacherDao.getTeacherListPageCount(teacher);
    }


    @Override
    public Long saveTeacher(Teacher teacher, Long classId) {
        Long teaId = teacherDao.saveTeacher(teacher);
        teacherDao.saveClassTeacherRela(classId, teaId, teacher.getCreater());
        return teaId;
    }

    @Override
    public void updateTeacher(Teacher teacher) {
        teacherDao.updateTeacher(teacher);
        teacherDao.deleteClassTeacherRelaByTeaId(teacher.getId());
        List<Class> clazzes = teacher.getClazz();
        for(Class clazz :clazzes){
            teacherDao.saveClassTeacherRela(clazz.getId(),teacher.getId() , teacher.getCreater());
        }
    }

    @Override
    public Teacher getTeacherById(Long id) {
        Teacher teacher = teacherDao.getTeacherById(id);
        return teacher;
    }


    @Override
    public void saveClassTeacherRela(Long classId, Long teaId, String creater) {
        teacherDao.saveClassTeacherRela(classId, teaId, creater);
    }

    @Override
    public void deleteTeacherById(Long teaId) {
        teacherDao.deleteClassTeacherRelaByTeaId(teaId);
        teacherDao.deleteTeacherById(teaId);
    }
}
